package com.tianquan.test.client;/**
 * @author starsea
 * @date 2024-11-04 下午4:58
 */

import com.tianquan.client.PBankClient;
import com.tianquan.client.loadBalan.BlockingLoadBalancerClient;
import com.tianquan.client.loadBalan.LoadBalancerClient;
import com.tianquan.client.loadBalan.strategy.LoadBalancerEnum;
import com.tianquan.miracle.annotation.Bean;
import com.tianquan.miracle.annotation.Configuration;

import java.io.IOException;
import java.util.Properties;

/**
 * @BelongsProject: Middleware
 * @BelongsPackage: com.tianquan.test.client
 * @Author: tianquan
 * @CreateTime: 2024-11-04  16:58
 * @Description:
 * @Version: 1.0
 */
@Configuration
public class config {

    // @Bean
    public PBankClient client() throws IOException {
        Properties properties = new Properties();
        properties.load(config.class.getClassLoader().getResourceAsStream("application.properties"));
        String url = properties.get("pbank.url").toString();
        Integer port = Integer.valueOf(properties.get("pbank.port").toString());
        String username = properties.get("pbank.username").toString();
        String password = properties.get("pbank.password").toString();
        String serverName = properties.get("server.name").toString();
        PBankClient client = PBankClient.PBankClientBuilder.builder()
                .user(username)
                .password(password)
                .serverName(serverName)
                .address(url)
                .port(port).build();
        new Thread(client::startClient).start();
        return client;
    }

    @Bean
    public LoadBalancerClient loadBalancerClient() throws IOException {
        BlockingLoadBalancerClient blockingLoadBalancerClient = new BlockingLoadBalancerClient(LoadBalancerEnum.RoundRobin);
        return blockingLoadBalancerClient;
    }


}
